package 栈和队列.包含main函数的栈;

import java.util.Stack;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/3/1 21:34
 * @description:剑指offer的题目
 * @version:
 */

//A是主栈，B是辅助栈
public class MinStack {
    Stack<Integer> A, B;
    public MinStack() {
        A = new Stack<>();
        B = new Stack<>();
    }
    public void push(int x) {
        A.add(x);
        if(B.empty() || B.peek() >= x)
            B.add(x);
    }
    public void pop() {
        if(A.pop().equals(B.peek()))
            B.pop();
    }
    public int top() {
        return A.peek();
    }
    public int min() {
        return B.peek();
    }

}
